DISCH EXPLAINS PPU WRITING -------------------------- - Disch explains the basics of writing background tiles to the PPU to Spliff in a random IRC excursion. **** BEGIN LOGGING AT Sat Dec 17 15:42:45 2005 Dec 17 15:42:45 * Now talking on #assembly Dec 17 15:42:49 * bbitmaster (~none@pcp02518652pcs.southk01.tn.comcast.net) has joined #assembly Dec 17 15:42:49 * Disch (disch_@dpc67143199073.direcpc.com) has joined #assembly Dec 17 15:42:52 * Spliff (Spliff@CPE00e0988e5616-CM014490005643.cpe.net.cable.rogers.com) has joined #assembly Dec 17 15:42:55 * Gavin has changed the topic to: Disch smells! Dec 17 15:42:58 Spliff Boo Dec 17 15:42:59 Disch har har Dec 17 15:43:01 * Gavin gives channel operator status to bbitmaster Dec 17 15:43:03 Disch lol Dec 17 15:43:03 * Gavin gives channel operator status to Disch Dec 17 15:43:04 bbitmaster lol, why here? Dec 17 15:43:05 * Gavin gives channel operator status to Spliff Dec 17 15:43:05 Disch anywayz Dec 17 15:43:11 Disch I don't know Dec 17 15:43:17 Spliff I have come to eat your viruz Dec 17 15:43:19 Spliff Submit! Dec 17 15:43:20 Disch I don't even really know what I was going to talk about any more Dec 17 15:43:24 Spliff Anywat Dec 17 15:43:27 Spliff PPU Dec 17 15:43:28 Gavin ll Dec 17 15:43:30 Gavin *lol Dec 17 15:43:40 Disch yeah okay Dec 17 15:44:10 Disch well for starters... you'd want to do all this when the PPU is inactive, since trying to write to the PPU while its drawing will cause craziness Dec 17 15:44:36 Disch so you can wait until VBLank -- or you can shut the PPU off by writing to $2001 Dec 17 15:44:48 Spliff Mmm Dec 17 15:45:03 Spliff What would I write, just any value? Dec 17 15:45:08 Disch Disabling both BG and sprite rendering puts the PPU in sort of an inactive state... making it save to do any nametable writes ot whatever Dec 17 15:45:08 Disch well Dec 17 15:45:17 Disch assuming you have a copy of nestech or some other doc Dec 17 15:45:31 Disch (which you probably should if you're attempting this kind of thing) Dec 17 15:45:44 Spliff I'm pretty sure I have it Dec 17 15:45:48 Disch in the $2001 description is has the following: Dec 17 15:46:14 Disch D4: Sprite Visibility 0 = Sprites not displayed 1 = Sprites visible Dec 17 15:46:29 Disch D3: Background Visibility 0 = Background not displayed 1 = Background visible Dec 17 15:46:49 Disch so if you want to turn off both BG and sprite rendering, you'd just make sure that whatever value you write has those bits off Dec 17 15:46:52 Disch $00 will work Dec 17 15:46:57 Disch so LDA #$00 STA $2001 Dec 17 15:47:07 Disch effectively turns off the PPU Dec 17 15:47:14 Spliff Ahhh Dec 17 15:47:39 Spliff I was a little confused there for a sec...Not quite sure what you meant, but that example helps Dec 17 15:47:53 Disch next... assuming you already have your pattern tables set up... you can just write the tiles to the name/attribute tables Dec 17 15:48:07 * Xin (internet@adsl-80-45-24.sdf.bellsouth.net) has joined #assembly Dec 17 15:48:21 Spliff How would I accomplish this? Dec 17 15:48:23 Disch the nametables are at $2xxx in PPU memory Dec 17 15:48:43 Disch PPU memory is different from CPU memory -- it's not really directly accessible. Dec 17 15:48:57 Disch You have to use the PPU I/O register ($2007) to write each byte to PPU memory Dec 17 15:49:11 Disch but first you have to set the address you want to write to -- this is done by writing to $2006 twice Dec 17 15:49:27 Disch first with the high byte of the desired address, and second with the low byte Dec 17 15:49:39 Disch so say for example, I want to change $2136 in PPU memory Dec 17 15:49:46 Disch I would set the address like so: Dec 17 15:49:49 Disch LDA #$21 Dec 17 15:49:51 Disch STA $2006 Dec 17 15:49:54 Disch LDA #$36 Dec 17 15:49:56 Disch STA $2006 Dec 17 15:50:06 Disch LDA _whatever_I_wanted_to_write_ Dec 17 15:50:16 Disch STA $2007 ; this gets written to $2136 in PPU mem Dec 17 15:51:04 Disch make sense? Dec 17 15:52:42 Spliff What does 2136 represent? Dec 17 15:52:43 * Disch wonders if he lost him Dec 17 15:52:48 Disch oh Dec 17 15:52:54 Disch well that was just as example address Dec 17 15:53:01 Spliff It's an example, I know, but what would it represent Dec 17 15:53:03 Disch $2136 is a random part of the nametable Dec 17 15:53:08 Spliff Ah Dec 17 15:53:16 Disch okay... it's like this Dec 17 15:53:25 Disch There is space for 4 nametables in PPU memory Dec 17 15:53:49 Disch if you will... think of 4 TV screens in a 2x2 square Dec 17 15:54:01 Disch each TV would represent a nametable Dec 17 15:54:33 Disch the upper-left nametable is at ppu$2000-23FF Dec 17 15:54:42 Disch the upper-right is at ppu$2400-27FF Dec 17 15:54:52 Disch lower-left at ppu$2800-2BFF Dec 17 15:54:58 Disch lower-right at ppu $2C00-2FFF Dec 17 15:55:36 Disch now if you don't want to get into scrolling or mirroring or any of that -- let's just assume you're only going to use the first nametable ($2000) Dec 17 15:56:20 Spliff Ok Dec 17 15:56:56 Disch the nametable is broken into two sections -- the actual 'name' section (which tells the tiles to draw) -- and the 'attribute' section (which tells what palette to give the tiles) Dec 17 15:57:31 Disch 1 byte in the nametable = 1 tile... and there are 32x30 tiles in a nametable Dec 17 15:57:53 Disch 32 * 30 = 960 = $3C0 Dec 17 15:58:03 Disch so $2000-$23BF is the actual nametable Dec 17 15:58:16 Disch and $23C0-$2FFF is the attribute table Dec 17 15:59:02 Spliff Understandable Dec 17 15:59:15 Disch so now if you wanted to just draw a picture and you didn't care what palette each tile used, you could do that by just writing values to $2000-23C0 Dec 17 15:59:20 Disch *$23BF Dec 17 15:59:22 Spliff But why on earth is it called a nametable if it stores tiles? Dec 17 15:59:34 * Disch shrugs Dec 17 15:59:39 Disch one of the many goofy names Dec 17 15:59:57 Spliff Lets call it a legobox Dec 17 16:00:05 Spliff little cubes of lego in a box Dec 17 16:00:13 Disch =P Dec 17 16:00:13 Spliff lego = tiles Dec 17 16:00:27 Gavin I would just rename it to "tile table", but whatever Dec 17 16:00:29 Disch anyway... you don't have to set the PPU address with $2006 for every tile Dec 17 16:00:43 Spliff Thats a question I was gonna ask before :p Dec 17 16:00:48 Disch the PPU will auto-increment the address on every $2007 write (and read, but don't worry about that) Dec 17 16:01:25 Disch it'll auto-increment by either 1 or 32... depending on what you set to the $2000 register ($2000.2) Dec 17 16:02:02 Disch (adding my 32 is useful if you want to draw a column of tiles... 1 is useful for doing rows -- or for filling the whole thing) Dec 17 16:02:09 Disch *adding by Dec 17 16:02:10 bbitmaster Were these names like "nametable" and "attribute table" actually what nintendo and their developers refferred to them as? or was it something that emulator developers and the folks that wrote the online tech docs came up with? Dec 17 16:02:30 bbitmaster er, sorry to interrupt... Dec 17 16:02:31 Disch I think nametable is an actual official term... but I don't really know Dec 17 16:02:42 bbitmaster ah Dec 17 16:02:55 Spliff It's probably a reverse engineering term brought in by the olden days hardware hackers who figured this out Dec 17 16:03:15 Spliff Possibly generic for all purposes Dec 17 16:03:18 Disch bbit: try Kabuki Quantum Fighter once... examine some of the 6502 it prints in the background during the intro Dec 17 16:04:32 Disch it says something like "LDA N2ATBL" or something Dec 17 16:04:52 Disch name-to-attribute? Dec 17 16:04:56 * Disch shrugs Dec 17 16:04:57 Disch anyways Dec 17 16:05:25 bbitmaster ah, interesting. Dec 17 16:06:00 Disch anyway... you can just set the PPU address to $2000 (by writes to $2006), then write $3C0 tiles to the nametable -- and you'll have a picture! Dec 17 16:06:08 Disch of course the palette will probably be all wrong Dec 17 16:06:54 Disch anyway... setting the palette is the same! (or at least very similar) Dec 17 16:07:03 Disch the palette is at $3F00-3F1F in ppu memory Dec 17 16:07:21 Disch so to change the palette, you set the address and write to $2007 in the same manner to set the colors Dec 17 16:09:04 Disch anyway that's about it Dec 17 16:09:27 Disch after you finish all that drawing, you just flip the screen on (write $18 to $2001 to enable BG+Sprite rendering) Dec 17 16:09:49 Disch and you might want to reset the PPU address (write $00 to $2006 twice) so that the screen won't be scrolled to some crazy spot Dec 17 16:10:54 Gavin Disch you previously mentioned VBlank Dec 17 16:11:06 Gavin perhaps an example of waiting for VBlank if the screen isn't off? Dec 17 16:11:53 Disch well you can't fill the entire nametable in VBlank -- so you'll have to turn the screen off anyway Dec 17 16:12:01 Disch (not enough time in VBlank) Dec 17 16:12:18 Disch at least I don't think there is Dec 17 16:12:24 Disch but anyway yeah Dec 17 16:12:43 Disch the easiest way to wait for VBlank is to watch the $2002 register Dec 17 16:12:54 Disch $2002.7 gets set when VBlank starts Dec 17 16:12:55 Disch so: Dec 17 16:13:04 Disch wait_for_VBlank: Dec 17 16:13:07 Disch LDA $2002 Dec 17 16:13:15 Disch BPL wait_for_VBlank Dec 17 16:14:12 Disch You shouldn't use that to regulate the flow of your game though... as it's possible for some VBlanks to be lost with that method (which would lead to a jerky game or even graphical glitches) Dec 17 16:14:22 Disch the best way to wait for VBlank is to enable NMIs Dec 17 16:14:40 Disch but I don't feel like getting into that now ;P Dec 17 16:14:43 Gavin that's basically what I did for that acid mario hack Dec 17 16:22:51 * Spliff has quit (Quit: HydraIRC -> http://www.hydrairc.com <- IRC has never been so good) Dec 17 17:45:06 * bbit (~none@pcp02518652pcs.southk01.tn.comcast.net) has joined #assembly Dec 17 17:45:14 * bbitmaster has quit (Killed (NickServ (GHOST command used by bbit))) Dec 17 17:45:18 * bbit is now known as bbitmaster Dec 17 18:56:06 * Xin has quit (cosmos.esper.net legend.esper.net) Dec 17 18:56:06 * Disch has quit (cosmos.esper.net legend.esper.net) Dec 17 18:57:22 * Xin (internet@adsl-80-45-24.sdf.bellsouth.net) has joined #assembly Dec 17 21:53:32 * bbitmaster (~none@pcp02518652pcs.southk01.tn.comcast.net) has left #assembly Dec 18 03:40:56 * Setzer (~Skiffles@dialup-4.155.117.151.Dial1.Baltimore1.Level3.net) has joined #assembly Dec 18 03:41:01 * Setzer (~Skiffles@dialup-4.155.117.151.Dial1.Baltimore1.Level3.net) has left #assembly Dec 18 13:18:47 * You are now known as Gavin|A Dec 18 14:13:45 * You are now known as Gavin Dec 18 14:44:11 * bbitmaster (~none@pcp02518652pcs.southk01.tn.comcast.net) has joined #assembly Dec 18 14:44:16 * bbitmaster (~none@pcp02518652pcs.southk01.tn.comcast.net) has left #assembly **** ENDING LOGGING AT Sun Dec 18 17:13:11 2005